<style>
    .table > tbody > tr > td > label.asterisk:after {
        content: " *";
        color: red;
    }
    .form-copy {
        width: 200px;
        margin-right: 5px;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px 7px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        border: 1px solid #ccc;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .select2 {
        margin-right: 5px
    }
</style>
<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h6 style="font-weight: bolder">基本信息(<span style="color: red">除tpl外均为本币</span>)</h6>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <tbody>
                <tr>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">国家</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <select id="country_id" name="country_id">
                            {{ getOptions(\App\Models\Basics\AmazonCountry::options()) }}
                        </select>
                    </td>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">SKU</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy" name="sku" placeholder="SKU">
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                </tbody>
            </table>
            <table class="table">
                <tbody>
                <tr>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">FBA费</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy amount_" name="fba_fee" placeholder="FBA费">
                    </td>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;" >销售价格</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy amount_" name="sale_price" placeholder="销售价格">
                    </td>
                    <td style="text-align: right;width: 100px;">

                    </td>
                    <td style="text-align: left;">

                    </td>
                </tr>
                </tbody>
            </table>
            <table class="table">
                <tbody>
                <tr>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">commission</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy amount_" name="commission" placeholder="Commission比率">
                    </td>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">退货</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy amount_" name="return" placeholder="退货比率">
                    </td>
                    <td style="text-align: right;width: 100px;">
                        <label style="padding-top: 8px;">VAT</label>
                    </td>
                    <td style="text-align: left;">
                        <input type="text" class="form-copy amount_" name="vat" placeholder="VAT比率">
                    </td>
                </tr>
                </tbody>
            </table>
            <table class="table">
                <tbody>
                <tr>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;">tpl(rmb)</label>
                    </td>
                    <td style="text-align: left;width: 200px;">
                        <input type="text" class="form-copy amount_" name="tpl_rmb" placeholder="tpl(rmb)">
                    </td>
                    <td style="text-align: right;width: 100px;">
                        <label class="asterisk" style="padding-top: 8px;" >重量(kg)</label>
                    </td>
                    <td style="text-align: left;">
                        <input type="text" class="form-copy amount_" name="weight" placeholder="重量(kg)">
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="box-footer">
    <div class="col-md-4"></div>
    {{ csrf_field() }}
    <button type="button" id="pro-form" class="btn btn-primary">提交</button>
</div>
<script language="JavaScript" type="text/javascript">
    function checkCodOForm(){
        var countryId = $('select[name="country_id"]').val();
        if(countryId == ''){
            swal('国家不能为空', '', 'error');
            return false;
        }
        var sku = $('input[name="sku"]').val();
        if(sku.trim() == ''){
            swal('SKU不能为空', '', 'error');
            return false;
        }
        var fbaFee = $('input[name="fba_fee"]').val();
        if(fbaFee == ''){
            swal('FBA费不能为空', '', 'error');
            return false;
        }
        var salePrice = $('input[name="sale_price"]').val();
        if(salePrice == ''){
            swal('销售价格不能为空', '', 'error');
            return false;
        }
        var commission = $('input[name="commission"]').val();
        if(commission == ''){
            swal('Commission比率不能为空', '', 'error');
            return false;
        }
        var _return = $('input[name="return"]').val();
        if(_return == ''){
            swal('退货比率不能为空', '', 'error');
            return false;
        }
        var tpl_rmb = $('input[name="tpl_rmb"]').val();
        if(tpl_rmb == ''){
            swal('tpl不能为空', '', 'error');
            return false;
        }
        var weight = $('input[name="weight"]').val();
        if(weight == ''){
            swal('重量不能为空', '', 'error');
            return false;
        }
        return true;
    }

    $(function () {
        $('#country_id').select2({placeholder: '国家', allowClear: true, width: '200px'});
        $(".amount_").inputmask("decimal",
            {
                digits: 3,
                onKeyValidation: function () {
                    if($(this).val() < 0){
                        $(this).val('');
                    }
                }
            }
        );
        var getParam = function () {
            var param = {};
            param['country_id'] = $('#country_id').val();
            param['sku_cn'] = $('input[name="sku"]').val().trim();
            param['fba_fee'] = $('input[name="fba_fee"]').val();
            param['sale_price'] = $('input[name="sale_price"]').val();
            param['commission'] = $('input[name="commission"]').val();
            param['return'] = $('input[name="return"]').val();
            param['vat'] = $('input[name="vat"]').val();
            param['tpl_rmb'] = $('input[name="tpl_rmb"]').val();
            param['weight'] = $('input[name="weight"]').val();
            return param;
        };
        $('#pro-form').on('click', function(e) {
            e.preventDefault();
            if(checkCodOForm()){
                var param = getParam();
                $.ajax({
                    method: 'post',
                    url: '/xqc/operation/profit-try-ajax',
                    data: {
                        _token:"{{ csrf_token() }}",
                        action:'addProfitTry',
                        param:param
                    },
                    success: function (data) {
                        if (typeof data === 'object') {
                            if (data.status) {
                                toastr.success('提交成功 !');
                            } else {
                                swal(data.message, '', 'error');
                            }
                        }
                    }
                });
            }
        });
    });
</script>
